#ifndef __WEBPAGEADAPTER_H_
#define __WEBPAGEADAPTER_H_

#include "webpage.h"
#include "pageprotocol.h"

#include "../../third/log4qt/src/log4qt/logger.h"
#include "../../third/log4qt/src/log4qt/basicconfigurator.h"
#include "../../third/log4qt/src/log4qt/propertyconfigurator.h"

class WebPageAdapter : public QObject {
    Q_OBJECT
    public :
        WebPageAdapter(WebPage* webpage, PageProtocol *client, WebSpiderRequest *req, QObject *parent = 0);
        ~WebPageAdapter();

        WebPage* page();
        void openUrl(const QString &address, const QVariant &op, const QVariantMap &settings, const QVariantList &cookie);
        void stop();
        void release();

        Operator *opt();

    private Q_SLOTS:
        void onInitialized();
        void onLoadStarted();
        void onLoadFinished(const QString &status);
        void onJavaScriptAlertSent(const QString &msg);
        void onJavaScriptConsoleMessageSent(const QString &message);
        void onJavaScriptErrorSent(const QString &msg, const QString &stack);
        void onResourceRequested(const QVariant &requestData, QObject *request);
        void onResourceReceived(const QVariant &resource);
        void onResourceError(const QVariant &errorData);
        void onResourceTimeout(const QVariant &errorData);
        void onUrlChanged(const QUrl &url);
        void onNavigationRequested(const QUrl &url, const QString &navigationType, bool navigationLocked, bool isMainFrame);
        void onRawPageCreated(QObject *page);
        void onClosing(QObject *page);
        void onSelfDestroyParse();
        void onTimeout();

    private:
        WebPage *m_page;
        PageProtocol *m_client;
        Operator *m_operator;
        QTimer m_failedTimer;
        Log4Qt::Logger *m_logger;
};

#endif

